package com.pandora;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;

public class App1 {
    public static void main(String args[]) throws IOException {
        //Blank Document
        XWPFDocument document= new XWPFDocument();

        //Write the Document in file system
        FileOutputStream out = new FileOutputStream(
                new File("c://create_table.docx"));

        //create table
        XWPFTable table = document.createTable(4,5);
        table.getRow(0).setHeight(900);

//        CTTblLayoutType type = table.getCTTbl().getTblPr().addNewTblLayout();
//        type.setType(STTblLayoutType.FIXED);


//        CTTblWidth width = table.getCTTbl().addNewTblPr().addNewTblW();
//        width.setType(STTblWidth.DXA);
//        width.setW(BigInteger.valueOf(8000));


//        CTTblWidth width = table.getCTTbl().addNewTblPr().addNewTblW();
//
//        width.setType(STTblWidth.DXA);
//        width.setW(BigInteger.valueOf(9500));


        for (int i = 0; i < table.getNumberOfRows(); i++) {
            XWPFTableRow row = table.getRow(i);
            int numCells = row.getTableCells().size();
            for (int j = 0; j < numCells; j++) {
                XWPFTableCell cell = row.getCell(j);
                CTTblWidth cellWidth = cell.getCTTc().addNewTcPr().addNewTcW();
                CTTcPr pr = cell.getCTTc().addNewTcPr();
                pr.addNewNoWrap();
                cellWidth.setW(BigInteger.valueOf(2880));
            }
        }


        document.write(out);
        out.close();
        System.out.println("create_table.docx written successully");
    }
}
